package com.xyc.javase.fortest;

/**
 * @Version 1.0
 * @Author:徐衍程
 * @Date:2022/3/22
 * @Content:递归
 */
public class Recursion {
    static class StopMsgException extends RuntimeException {
    }
    public static void main(String[] args) {
        //中断递归：抛异常的方式
        try {
            run(10);
        }catch (StopMsgException e){
            System.out.println(e.getMessage());
        }
        System.out.println("捕获异常继续往下执行！");
    }
    public static void run(int t) {

        if (t > 20) {
            // 跳出
            throw new StopMsgException();
        }
        // 执行操作
        System.out.println(t);
        // 递归
        run(t + 1);
    }
}
